package com.example.springboot.demo.conf;

import com.example.springboot.demo.model.User;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SessionHandlerInterceptor implements HandlerInterceptor  {

    @Override
    public boolean preHandle (HttpServletRequest request , HttpServletResponse response , Object handler) throws IOException {
        User user = new User();
        if(user==null){
                response.sendRedirect("/login.html");
                return false;
        }
        return  true;
    }

    public void  postHandle(HttpServletRequest request , HttpServletResponse response , Object handler) throws IOException {


        //controller 方法处理完毕后调用此方法
        System.out.println("controller完成");
    }


    public void  afterCompletion(HttpServletRequest request , HttpServletResponse response , Object handler) throws IOException {
        //页面渲染完毕后调用此方法
        System.out.println("页面渲染完成");

    }



}
